# 引入hashlib ,为了加密登录密码
import hashlib


import requests

# -------------------------登录------------------------------
# 构造请求头
headers = {

    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
    'Content-Type': 'application/json;charset=utf-8'
}
# 'token': ''

# 构造url
base_url = r'https://cloud.huaxiaerp.com/'
url_login = base_url + '/jshERP-boot/user/login'

# 构造data
username = 'Missing'
password = 'h123456'
md5 = hashlib.md5(password.encode())  # 创建MD5对象
password_md5 = md5.hexdigest()  # 调用方法hexdigest加密
data_login = {
    "loginName": username,
    "password": password_md5
}
# 发送情求
resp = requests.post(url_login, json=data_login, headers=headers, verify=False)

# 获取响应
token = resp.json()['data']['token']
print(token)

# --------------------------角色管理：新增------------------------------
# 构造headers
headers['X-Access-Token'] = token  # 新增token
# # 构造url
# url_role = base_url + '/jshERP-boot/role/add'
# # 构造数据
# name = '天冰1'
# type = '本机构数据'
# data_role_add = {
#     "name": name,
#     "type": type
# }
# # 发送请求
# resp = requests.post(url_role, headers=headers, json=data_role_add, verify=False)
# # 获取响应
# print(resp.text)

# *********************************************** 授权限 ****************************************************
# url_role_auth_add = base_url + '/jshERP-boot/userBusiness/add'
# # 构造数据
# data_role_add_auth = {
#     "type": "RoleFunctions", "keyId": 10250,
#     "value": [0, 225, 210, 211, 32, 241, 33, 199, 38, 242, 41, 200, 239, 201, 202, 40, 232, 233, 257, 258, 259, 44,
#               197, 203, 204, 205, 206, 212, 269, 254, 255, 273, 256, 198, 260, 207, 283, 208, 209, 226, 227, 263, 228,
#               229, 59, 235, 237, 244, 282, 275, 276, 248, 249, 274, 250, 247, 264, 266, 267, 271, 21, 22, 23, 220, 262,
#               285, 24, 25, 217, 218, 26, 194, 195, 31, 246, 261]
# }
# # 发送请求
# resp = requests.post(url_role_auth_add, headers=headers, json=data_role_add_auth, verify=False)
# # 获取响应
# print(resp.text)
#
# # *****************************************88**************** 分按钮 *******************
# url_role_btn_add = base_url + '/jshERP-boot/userBusiness/updateBtnStr'
# # 构造数据
# data_role_add_btn = {
#     "roleId": 10250,
#     "btnStr": "[{\"funId\":22,\"btnStr\":\"1\"},{\"funId\":23,\"btnStr\":\"1,3\"},{\"funId\":220,\"btnStr\":\"1\"},{\"funId\":262,\"btnStr\":\"1\"},{\"funId\":25,\"btnStr\":\"1,3\"},{\"funId\":217,\"btnStr\":\"1,3\"},{\"funId\":218,\"btnStr\":\"1,3\"},{\"funId\":26,\"btnStr\":\"1\"},{\"funId\":194,\"btnStr\":\"1\"},{\"funId\":195,\"btnStr\":\"1\"},{\"funId\":31,\"btnStr\":\"1\"},{\"funId\":246,\"btnStr\":\"1\"},{\"funId\":261,\"btnStr\":\"1\"},{\"funId\":241,\"btnStr\":\"1,2,3,7\"},{\"funId\":33,\"btnStr\":\"1,2,3,7\"},{\"funId\":199,\"btnStr\":\"1,2,3,7\"},{\"funId\":242,\"btnStr\":\"1,2,3,7\"},{\"funId\":41,\"btnStr\":\"1,2,3,7\"},{\"funId\":200,\"btnStr\":\"1,2,3,7\"},{\"funId\":210,\"btnStr\":\"1,2,3,7\"},{\"funId\":211,\"btnStr\":\"1,2,3,7\"},{\"funId\":258,\"btnStr\":\"1,2,3,7\"},{\"funId\":259,\"btnStr\":\"1,2,3,7\"},{\"funId\":197,\"btnStr\":\"1,2,3,7\"},{\"funId\":203,\"btnStr\":\"1,2,3,7\"},{\"funId\":204,\"btnStr\":\"1,2,3,7\"},{\"funId\":205,\"btnStr\":\"1,2,3,7\"},{\"funId\":206,\"btnStr\":\"1,2,3,7\"},{\"funId\":212,\"btnStr\":\"1,2,3,7\"},{\"funId\":269,\"btnStr\":\"1\"},{\"funId\":255,\"btnStr\":\"1,2,7\"},{\"funId\":273,\"btnStr\":\"1,2,7\"},{\"funId\":256,\"btnStr\":\"1,3\"},{\"funId\":271,\"btnStr\":\"1\"},{\"funId\":201,\"btnStr\":\"1,2,3,7\"},{\"funId\":202,\"btnStr\":\"1,2,3,7\"},{\"funId\":40,\"btnStr\":\"1,2,3,7\"},{\"funId\":232,\"btnStr\":\"1,2,3,7\"},{\"funId\":233,\"btnStr\":\"1,2,3,7\"}]"
# }
# # 发送请求
# resp = requests.post(url_role_btn_add, headers=headers, json=data_role_add_btn, verify=False)
# # 获取响应
# print(resp.text)

# ----------------------------角色管理：启用------------------------------------------
# url_on = base_url + '/jshERP-boot/role/batchSetStatus'
# # # 构造数据
# # data_on = {
# #     "status":True,
# #     "ids":"10249,"
# # }
# # # 发送请求
# # resp = requests.post(url_on,headers=headers,json=data_on,verify=False)
# # print(resp.text)
# # ----------------------------角色管理：禁用------------------------------------------
# # 构造数据
# data_on = {
#     "status":False,
#     "ids":"10249,"
# }
# resp = requests.post(url_on,headers=headers,json=data_on,verify=False)
# print(resp.text)

# # ----------------------------角色管理：修改------------------------------------------
# # 构造url
# url_role_mod = base_url + '/jshERP-boot/role/update'
# # 构造数据
# id = 10251
# name = '天冰2'
# type = '本机构数据'
# data_role_mod = {
#     "deleteFlag": "0",
#     "enabled": True,
#     "id": id,
#     "name": name,
#     "tenantId": 151170,
#     "type": type
# }
# # 发送请求
# resp = requests.put(url_role_mod, headers=headers, json=data_role_mod, verify=False)
# # 获取响应
# print(resp.text)

# # ----------------------------角色管理：查询------------------------------------------
# # 构造url
# url_role_query = base_url + '/jshERP-boot/role/list'
# # 构造数据
# name = '天冰2'
# description = ''
# # 把内层字典单独定义
# search_dic = {"name":name,"description":description}
# # 把内层字典转换成字符串类型
# search_str = json.dumps(search_dic)
# data_role_query = {
#     'search': search_str,
#     'column': 'createTime',
#     'order': 'desc',
#     'field': ['id', '', '', 'action', 'name', 'type', 'priceLimitStr', 'description', 'sort', 'enabled'],
#     'currentPage': 1,
#     'pageSize': 10
# }
# # 发送请求
# resp = requests.get(url_role_query,headers=headers,params=data_role_query)
# # 获取响应
# print(resp.text)

# # ----------------------------角色管理：删除------------------------------------------
# # 构造url
# url_role_delete = base_url + '/jshERP-boot/role/delete'
# # 构造数据
# id = 10282
# data_role_delete = {
#     'id': id
# }
# # 发送请求
# resp = requests.delete(url_role_delete,params=data_role_delete,headers=headers)
# # 获取响应
# print(resp.text)
